﻿@{
    ViewBag.Title = "YueDu";
}
@model MVCforPhotoWall.Models.LineModel

<!DOCTYPE html>
<h2>阅读：@Model.FileName</h2>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <title></title>
</head>
<body>
    <div>
        <p>当前行：@Model.LineNumber/@Model.TotalLines</p>
        <p>@Model.Line</p>
    </div>
    <div>
        <label>批注</label>
        <textarea id="note" rows="4" cols="50">@Model.Note</textarea>
        <br />
        @*<button onclick="saveNote('@Model.FileName', '@Model.LineNumber')">保存批注</button>*@
        <button onclick="saveNote()">保存批注</button>
        @*<button id="btnSaveNote">保存批注</button>*@
    </div>
    <div>
        <a href="@Url.Action("Read","BookList", new {filename = Model.FileName,lineNumber= Model.LineNumber-1 })"
           class="btn btn-primary" @(Model.LineNumber == 1 ? "disable" : "")>上一页</a>
        <a href="@Url.Action("Read","BookList", new {filename = Model.FileName,lineNumber= Model.LineNumber+1 })"
           class="btn btn-primary" @(Model.LineNumber == Model.TotalLines ? "disable" : "")>下一页</a>
    </div>
    <script src="~/Scripts/jquery-3.5.1.min.js"></script>
    <script>
        //$(document).ready(
        //    function () {
        //        $('#btnSaveNote').click(
        //            function () {
        //                alert("sssss");
        //            }
        //        );
        //    }
        //);
        function saveNote() {
            var notete = document.getElementById('note').value;
            @*$.ajax({
                url: '@Url.Action("SaveNote","BookList")',
                type: 'POST',
                data: {
                    fileNmae: @Model.FileName,
                    lineNumber: @Model.LineNumber,
                    lineWord:@Model.Line,
                    note: note,
                },
                success: function () {
                    alert('批注已保存');
                },
                error: function () {
                    alert('保存批注时出错');
                }
                });*@
            var data = { fileName: '@Model.FileName', lineNumber: '@Model.LineNumber', lineWord: '@Model.Line', note: notete };

            $.ajax({
                    url: '@Url.Action("SaveNote", "BookList")', // 请求的URL
                    type: 'POST', // 请求类型
                    data:{ fileName: '@Model.FileName', lineNumber: '@Model.LineNumber', lineWord: '@Model.Line', note: notete }, // 要发送的数据
                    success: function (data) { // 请求成功时的回调函数
                        alert('批注已保存');
                    },
                    error: function () { // 请求失败时的回调函数
                        alert('保存批注时出错');
                    }
                });
        }
    </script>
</body>
</html>
